#define DEBUG
#include <cstdio>
#define MAXN 1000
#define MAXM 1000

using namespace std;

long long getDis(int x, int y, char map[MAXN+1][MAXM+1], int ver, int n, int m) {
  const int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
  static int book[MAXN+1][MAXM+1], dis[MAXN+1][MAXM+1], que[MAXN*MAXM+1][2];
  que[1][0] = x, que[1][1] = y;
  dis[x][y] = 0;
  book[x][y] = ver;
  for (int h=0, t=1; h<t; ) {
    h++;
    int x = que[h][0], y = que[h][1];
    for (int i=0; i<4; i++) {
      int nx = x+dir[i][0], ny = y+dir[i][1];
      if (nx>0 && ny>0 && nx<=n && ny<=m && map[nx][ny]!='X') {
	if (dis[nx][ny]>dis[x][y]+1 || book[nx][ny]!=ver) {
	  dis[nx][ny] = dis[x][y]+1;
	  if (book[nx][ny]!=ver) {
	    book[nx][ny] = ver;
	    t++;
	    que[t][0] = nx, que[t][1] = ny;
	  }
	}
      }
    }
  }
  
  long long ret=0;
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      if (map[i][j]=='.') {
	ret = ret+dis[i][j];
      }
    }
  }
  return ret;
}

int main() {
#ifdef DEBUG
  freopen("2.in", "r", stdin);
  freopen("2.out", "w", stdout);
#endif

  static char map[MAXN+1][MAXM+1];
  int n, m;
  scanf("%d %d ", &n, &m);
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      map[i][j] = getchar();
    }
    getchar();
  }
  
  long long dis=0, cnt=0;
  for (int i=1; i<=n; i++) {
    for (int j=1; j<=m; j++) {
      if (map[i][j]!='X') {
	dis += getDis(i, j, map, i*m+j-m, n, m);
	cnt++;
      }
    }
  }

  printf("%.4LF", (long double)dis/(cnt*cnt));

  fclose(stdin);
  fclose(stdout);
  return 0;
}
